﻿using System.Windows;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;
using MyFloridaHouse.libSvUtilities.Logging;
using System;
using System.Collections.Generic;
using MyFloridaHouse.libSvCommonUtilities;
using MyFloridaHouse.libSvUtilities;


namespace MyFloridaHouse.libSvMassDataReport.Reports
{
    public partial class ACSDistrictSummary
    {

        private void GetACSReportDefinition()
        {
            // load up the static data
            serviceDAL.GetACSReportDefinition(GetACSReportDefinitionCompleted);
        }

        public void GetACSReportDefinitionCompleted(object sender, GetACSReportDefinitionCompletedEventArgs args)
        {
            try
            {
                serviceDAL.getACSReportDefinitionRequestCount--;
                
                // error in WCF service call
                if (Log.HandleException(args.Error)) return;

                // unknown error in the service method
                if (args.Result == null)
                {
                    MessageBox.Show("Error getting ACS District Summary Report Definition " + args.Error.Message.ToString());
                }
                else
                {
                    // caught error in the service method
                    if (Log.HandleServerError("GetACSReportDefinitionCompleted", args.Result.errorMessage)) return;
                    // Everything OK!

                    var serializedList = CompressionManager.DecompressToByteArray(args.Result.results);
                    var serviceMsg = (ACSDistrictSummaryReportDefinitionListDTO)SerializationManager.Deserialize(typeof(ACSDistrictSummaryReportDefinitionListDTO), serializedList);
                    LoadACSDistrictSummaryReportDefintion(serviceMsg.ACSDistrictSummaryReportDefinitionList);
                }
            }
            catch (Exception ex)
            {
                Log.HandleException(ex);
            }
        }
    }
}
